package com.otp.webapp.action.util;

import java.util.Iterator;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.component.UISelectOne;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

public class RequiredFieldsValidator implements Validator {    
	
public void validate(FacesContext context, UIComponent component,Object value) throws ValidatorException {
    	FacesMessage msg = null;
        String strValue = (String) value;


        UISelectOne selectComponent = (UISelectOne) component;
        String submitVal = (String) selectComponent.getSubmittedValue();

        if (strValue == null || strValue.isEmpty() || submitVal == null || submitVal.isEmpty()) {
        	Iterator<FacesMessage> msgIterator = FacesContext.getCurrentInstance().getMessages();
        	if(msgIterator==null || !msgIterator.hasNext()){
        		msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "All the question in this section should be answered", null);
        		throw new ValidatorException(msg);
        	}
        		
            
            
        }
        
        
        
        


    }
}
